<template>
	<view style="background: rgba(72, 72, 72, 0.7);">
		<cu-custom :isBack="false" bgColor="bg-white solids-bottom text-darkGray">
			<block slot="content">
				新闻公告
			</block>
			<block slot="right"></block>
		</cu-custom>
		<view class="warp30" style="background:none;"></view>
		<view>
			<view class="model-main model">
				<navigator :url="'/pagesB/newsdetail/newsdetail?detailDate='+encodeURIComponent(JSON.stringify(item))" class="uni-row model-item" v-for="item in listData" :key="item.Id">
					<view class="margin-bottom cu-avatar-box">
						<!-- <view class="uni-flex margin-bottom-sm">
							<view class="cu-avatar lg round margin-right" :style="'background-image:url('+'https://ossweb-img.qq.com/images/lol/web201310/skin/big25002.jpg'+');'"></view>
							<view style="flex: 1;">
								<view class="cu-avatar-name">{{item.UserName}}</view>
								<view class="cu-avatar-num"><text class="margin-right-sm">{{item.Line1Display}}</text></view>
							</view>
						</view> -->
						<view class="cu-avatar-main margin-bottom-sm">
							<!-- {{item.Abstract}} -->{{item.title}}
						</view>
						<view class="cu-avatar-photo clearfix">
							<view v-for="(img,index) in item.Pics" v-if="item.Pics.length>1&&index<4" :key="index" style="width: calc(50vw - 42upx);height: calc(15.75vw - 13.23upx);float: left;margin: 0 6upx 6upx;overflow: hidden;">
								<image :src="img" style="width: 100%;" mode="widthFix"></image>
							</view>
							<view v-for="(img,index) in item.Pics" v-if="item.Pics.length==1" :key="index" style="width: calc(100vw - 72upx);height: calc(31.5vw - 22.7upx);float: left;margin: 0 6upx 6upx;overflow: hidden;">
								<image :src="img" style="width: 100%;" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</navigator>
				<!-- <uni-load-more :loadingType="loadingType" :contentText="contentText"></uni-load-more> -->
			</view>
		</view>
		<view class="warp30"></view>
		<view class="cu-tabbar-height wx"></view>
	</view>
</template>

<script>
	/* import uniLoadMore from '../../../components/uni-load-more.vue' */
	export default {
		/* components: {
			uniLoadMore
		}, */
		data() {
			return {
				listData: [],
				reload: false,
				loadingType: 0,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				},
				page: 1,
			};
		},
		onLoad:function(){
			// #ifdef MP-WEIXIN
			var _this = this;
			wx.cloud.init();
			const db = wx.cloud.database()
			const getCount = async function(){
				const countResult = await db.collection('wiki_news').count()
				const total = countResult.total;
				const batchTimes = Math.ceil(total / 20);
				const tasks = []
				for (let i = 0; i < batchTimes; i++) {
					const promise = db.collection('wiki_news').skip(i * 20).limit(20).get();
					tasks.push(promise)
				}
				return (await Promise.all(tasks)).reduce((acc, cur) => {
					let data = cur.data;
					acc.data = acc.data.concat(...data);
					return {
						data: acc.data,
						errMsg: acc.errMsg,
					}
				})
			}
			const wikidata = getCount();
			wikidata.then(function(result){
				_this.listData = result.data;
				_this.listData.map(item => {
					item.Pics = item.imgStr===""? [] : item.imgStr.split(",");
					console.info(item.Pics,item.imgStr);
				});
				console.info(result.data);
			});
			// #endif
			/* this.getList(); */
		},
		/* onPullDownRefresh() {
			this.reload = true;
			this.getList();
		},
		onReachBottom() {
			if (this.loadingType !== 0) {
				return;
			}
			this.loadingType = 1;
			this.getList();
		},
		methods: {
			getList() {
				var data = {
					"PageIndex": this.page,
					"PageSize": 5
				};
				uni.request({
					url: this.AjaxUrl + '/WebApi/GetX3NewsList',
					data: data,
					success: (res) => {
						uni.stopPullDownRefresh();
						if (res.statusCode == 200) {
							let list = JSON.parse(res.data.Extend).List;
							let PageCount = JSON.parse(res.data.Extend).PageCount;
							if (this.page > PageCount) {
								this.loadingType = 2;
								return;
							}
							this.listData = this.reload ? list : this.listData.concat(list);
							this.reload = false;
							this.page++;
							this.loadingType = 0;
							console.info(this.listData,JSON.parse(res.data.Extend));
						}
					},
					fail: (e) => {
						console.info(e);
					}
				})
			},
			setTime: function(items) {
				var newItems = [];
				items.forEach((e) => {
					newItems.push({
						Id: e.Id,
						PicSrc: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/shuijiao.jpg",
						UserName: e.UserName,
						Line1Display: e.Line1Display,
						Abstract: e.Abstract,
						Pics: e.Pics
					});
				});
				return newItems;
			},
			moveHandle: function() {
				console.info("滑不了了");
			},
		} */
	}
</script>

<style lang="less">
.model-main>.uni-row.model-item{
	padding: 30upx;
	overflow: hidden;
	position: relative;
	view{color:#ffffff;font-size: 36upx;}
	&:after{
		content: "";
		display: block;
		height: 2upx;
		width: 100%;
		background: #ffffff;
		left: 30upx;
		bottom: 0;
		position: absolute;
	}
	&:last-child:after{
		display: none;
	}
	.cu-avatar-box{
		.cu-avatar-name{
			font-size: 32upx;
			color: #ffffff;
			line-height: 48upx;
		}
		.cu-avatar-num{
			font-size: 28upx;
			color: #ffffff;
			line-height: 48upx;
		}
		.cu-avatar-main{
			line-height: 1.5;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 3;
			-webkit-box-orient: vertical;
		}
	}
}
</style>
